package com.ch.web.controller;

import com.ch.web.entity.user.XyBackCommentEntity;
import com.ch.web.service.XyBackCommentService;
import com.ch.web.utils.ConstUtils;
import com.ch.web.utils.PageUtils;
import com.ch.web.utils.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;


/**
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-10-15 13:58:33
 */
@RestController
@RequestMapping("xy/backComment")
public class XyBackCommentController {
    @Autowired
    private XyBackCommentService xyBackCommentService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = xyBackCommentService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id) {
        XyBackCommentEntity xyBackComment = xyBackCommentService.getById(id);

        return R.ok().put("xyBackComment", xyBackComment);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody XyBackCommentEntity xyBackComment) {
        xyBackCommentService.save(xyBackComment);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")

    public R update(@RequestBody XyBackCommentEntity xyBackComment) {
        xyBackCommentService.updateById(xyBackComment);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")

    public R delete(@RequestBody Long[] ids) {
        xyBackCommentService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

    /**
     * 保存
     */
    @RequestMapping("/add")
    public R add(@RequestBody XyBackCommentEntity xyBackComment) {
        if (xyBackCommentService.addBackComment(xyBackComment)) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("id", xyBackComment.getId());
            map.put("createTime", ConstUtils.getCurrentTime());
            return R.ok(map);
        } else {
            return R.error();
        }
    }
}
